
package es.ucm.disia.xsdp.wizard;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;

public class Panel1 extends JPanel
{
	private static final long serialVersionUID = 1L;
	// Botones
	private JButton botCompilar = new JButton();

	// Contenedores
	private Box box1;
	private Box box2;

	private JScrollPane jScrollPane1 = new JScrollPane();
	private JScrollPane jScrollPane2 = new JScrollPane();
	private JTextArea codigoFuente = new JTextArea();
	private JTextArea codigoObjeto = new JTextArea();

	// Etiquetas
	private JLabel labelCodFu = new JLabel();
	private JLabel labelCodObj = new JLabel();

	private MainFrame padreGUI;

	public Panel1(MainFrame frame) {
		super();
		padreGUI = frame;
		try
		{
			jbInit();
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	private void jbInit() throws Exception
	{
		this.setBackground(SystemColor.info);
		this.setMinimumSize(new Dimension(780, 481));
		this.setPreferredSize(new Dimension(780, 481));
		this.setLayout(null);

		crearEtiquetas();
		crearBotones();
		crearAcciones();

		this.add(jScrollPane1, null);
		this.add(labelCodFu, null);
		this.add(jScrollPane2, null);
		this.add(labelCodObj, null);
		this.add(botCompilar, null);
	}

	private void crearBotones()
	{
		botCompilar.setText("PARSE");
		botCompilar.setBounds(new Rectangle(438, 418, 91, 27));
		botCompilar.setFont(new java.awt.Font("Serif", 1, 11));

		codigoFuente.setFont(new java.awt.Font("Monospaced", 0, 11));
		codigoFuente.setEditable(false);
		codigoObjeto.setFont(new java.awt.Font("Monospaced", 2, 11));
		codigoObjeto.setForeground(UIManager.getColor("Button.light"));
		codigoObjeto.setDisabledTextColor(SystemColor.inactiveCaptionText);
		codigoObjeto.setEditable(false);
		codigoObjeto.setSelectionColor(SystemColor.activeCaption);

		box1 = Box.createHorizontalBox();
		jScrollPane1.setBounds(new Rectangle(28, 53, 501, 342));
		jScrollPane2.setBounds(new Rectangle(598, 53, 322, 340));

		box1.add(codigoFuente, null);
		box2 = Box.createHorizontalBox();
		box2.add(codigoObjeto, null);

		jScrollPane1.getViewport().add(box1, null);
		jScrollPane2.getViewport().add(box2, null);
	}

	private void crearEtiquetas()
	{
		labelCodFu.setFont(new java.awt.Font("DialogInput", 0, 14));
		labelCodFu.setForeground(Color.blue);
		labelCodFu.setOpaque(false);
		labelCodFu.setHorizontalAlignment(SwingConstants.LEFT);
		labelCodFu.setHorizontalTextPosition(SwingConstants.CENTER);
		labelCodFu.setText("File:");
		labelCodFu.setBounds(new Rectangle(31, 22, 208, 25));

		labelCodObj.setText("Result:");
		labelCodObj.setBounds(new Rectangle(598, 24, 208, 25));
		labelCodObj.setHorizontalTextPosition(SwingConstants.CENTER);
		labelCodObj.setHorizontalAlignment(SwingConstants.LEFT);
		labelCodObj.setOpaque(false);
		labelCodObj.setFont(new java.awt.Font("DialogInput", 0, 14));
		labelCodObj.setForeground(Color.gray);
	}

	private void crearAcciones()
	{
		// Compilar
		botCompilar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				compilar();
			}
		});
	}

	public void limpiarCodFu()
	{
		codigoFuente.setText("");
	}

	public void limpiarCodObj()
	{
		codigoObjeto.setText("");
	}

	public String dameCodFu()
	{
		return codigoFuente.getText();
	}

	public String dameCodObj()
	{
		return codigoObjeto.getText();
	}

	public void ponCodFu(String programa)
	{
		codigoFuente.setText(programa);
	}

	public void compilar()
	{
		padreGUI.nuevo();
		padreGUI.compilar();
	}

	public void setResul(String resul)
	{
		limpiarCodObj();
		codigoObjeto.setText(resul);		
	}

	public void representarArb(DefaultMutableTreeNode arb)
	{
		padreGUI.representarArbol(arb);
	}
}